/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layouts";
import EmptyLayout from "@/layouts/EmptyLayout";
import { publicPath, routerMode } from "@/config";

Vue.use(VueRouter);
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/register",
    component: () => import("@/views/register/index"),
    hidden: true,
  },
  {
    path: "/401",
    name: "401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true,
  },
];

export const asyncRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "index",
        name: "Index",
        component: () => import("@/views/index/index"),
        meta: {
          title: "首页",
          icon: "home",
          affix: true,
        },
      },
    ],
  },
  {
    path: "/goodsManagement",
    component: Layout,
    redirect: "noRedirect",
    name: "GoodsManagement",
    meta: {
      title: "物资管理",
      icon: "shipping-fast",
      permissions: ["admin"],
    },
    children: [
      {
        path: "inWarehouse",
        name: "InWarehouse",
        component: () => import("@/views/goodsManagement/inWarehouse/index"),
        meta: {
          title: "入库",
          noKeepAlive: true,
        },
      },
      {
        path: "inWarehousetMobileEdit",
        name: "InWarehousetMobileEdit",
        component: () =>
          import(
            "@/views/goodsManagement/inWarehouse/components/InWarehousetMobileEdit"
          ),
        meta: {
          title: "入库",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-入库")
            : (to.meta.title = "添加-入库");
          next();
        },
      },
      {
        path: "outWarehouse",
        name: "OutWarehouse",
        component: () => import("@/views/goodsManagement/outWarehouse/index"),
        meta: {
          title: "出库",
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: "/farmingManagement",
    component: Layout,
    redirect: "noRedirect",
    name: "FarmingManagement",
    meta: {
      title: "养殖管理",
      icon: "paw",
      permissions: ["admin"],
    },
    children: [
      {
        path: "user",
        name: "User",
        component: () => import("@/views/farmingManagement/user/index"),
        meta: {
          title: "人员",
          noKeepAlive: true,
        },
      },
      {
        path: "userMobileEdit",
        name: "UserMobileEdit",
        component: () =>
          import("@/views/farmingManagement/user/components/UserMobileEdit"),
        meta: {
          title: "人员",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-人员")
            : (to.meta.title = "添加-人员");
          next();
        },
      },
      {
        path: "salary",
        name: "Salary",
        component: () => import("@/views/farmingManagement/salary/index"),
        meta: {
          title: "薪资(按月份/人)",
          noKeepAlive: true,
        },
      },
      {
        path: "salaryMobileEdit",
        name: "SalaryMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/salary/components/SalaryMobileEdit"
          ),
        meta: {
          title: "薪资(按月份/人)",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-薪资")
            : (to.meta.title = "添加-薪资");
          next();
        },
      },
      {
        path: "variety",
        name: "Variety",
        component: () => import("@/views/farmingManagement/variety/index"),
        meta: {
          title: "品种",
          noKeepAlive: true,
        },
      },
      {
        path: "varietyMobileEdit",
        name: "VarietyMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/variety/components/VarietyMobileEdit"
          ),
        meta: {
          title: "品种",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-品种")
            : (to.meta.title = "添加-品种");
          next();
        },
      },
      {
        path: "survive",
        name: "Survive",
        component: () => import("@/views/farmingManagement/survive/index"),
        meta: {
          title: "存活记录",
          noKeepAlive: true,
        },
      },
      {
        path: "surviveMobileEdit",
        name: "SurviveMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/survive/components/SurviveMobileEdit"
          ),
        meta: {
          title: "存活记录",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-存活记录")
            : (to.meta.title = "添加-存活记录");
          next();
        },
      },
      {
        path: "vaccine",
        name: "Vaccine",
        component: () => import("@/views/farmingManagement/vaccine/index"),
        meta: {
          title: "疫苗",
          noKeepAlive: true,
        },
      },
      {
        path: "vaccineMobileEdit",
        name: "VaccineMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/vaccine/components/VaccineMobileEdit"
          ),
        meta: {
          title: "疫苗",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-疫苗")
            : (to.meta.title = "添加-疫苗");
          next();
        },
      },
      {
        path: "vaccinePlan",
        name: "VaccinePlan",
        component: () => import("@/views/farmingManagement/vaccinePlan/index"),
        meta: {
          title: "疫苗计划表",
          noKeepAlive: true,
        },
      },
      {
        path: "vaccinePlanMobileEdit",
        name: "VaccinePlanMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/vaccinePlan/components/VaccinePlanMobileEdit"
          ),
        meta: {
          title: "疫苗计划表",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-疫苗计划表")
            : (to.meta.title = "添加-疫苗计划表");
          next();
        },
      },
      {
        path: "env",
        name: "Env",
        component: () => import("@/views/farmingManagement/env/index"),
        meta: {
          title: "环境控制",
          noKeepAlive: true,
        },
      },
      {
        path: "envMobileEdit",
        name: "EnvMobileEdit",
        component: () =>
          import("@/views/farmingManagement/env/components/EnvMobileEdit"),
        meta: {
          title: "环境控制",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-环境控制")
            : (to.meta.title = "添加-环境控制");
          next();
        },
      },
      {
        path: "feed",
        name: "Feed",
        component: () => import("@/views/farmingManagement/feed/index"),
        meta: {
          title: "饲喂",
          noKeepAlive: true,
        },
      },
      {
        path: "feedMobileEdit",
        name: "FeedMobileEdit",
        component: () =>
          import("@/views/farmingManagement/feed/components/FeedMobileEdit"),
        meta: {
          title: "饲喂",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-饲喂")
            : (to.meta.title = "添加-饲喂");
          next();
        },
      },
      {
        path: "feedPlan",
        name: "FeedPlan",
        component: () => import("@/views/farmingManagement/feedPlan/index"),
        meta: {
          title: "饲喂计划表",
          noKeepAlive: true,
        },
      },
      {
        path: "feedPlanMobileEdit",
        name: "FeedPlanMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/feedPlan/components/FeedPlanMobileEdit"
          ),
        meta: {
          title: "饲喂计划表",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-饲喂计划表")
            : (to.meta.title = "添加-饲喂计划表");
          next();
        },
      },
      {
        path: "garbage",
        name: "Garbage",
        component: () => import("@/views/farmingManagement/garbage/index"),
        meta: {
          title: "废弃处理",
          noKeepAlive: true,
        },
      },
      {
        path: "garbageMobileEdit",
        name: "GarbageMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/garbage/components/GarbageMobileEdit"
          ),
        meta: {
          title: "废弃处理",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-废弃处理")
            : (to.meta.title = "添加-废弃处理");
          next();
        },
      },
      {
        path: "poultry",
        name: "Poultry",
        component: () => import("@/views/farmingManagement/poultry/index"),
        meta: {
          title: "禽蛋管理",
          noKeepAlive: true,
        },
      },
      {
        path: "poultryMobileEdit",
        name: "PoultryMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/poultry/components/PoultryMobileEdit"
          ),
        meta: {
          title: "禽蛋管理",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-禽蛋管理")
            : (to.meta.title = "添加-禽蛋管理");
          next();
        },
      },
      {
        path: "repair",
        name: "Repair",
        component: () => import("@/views/farmingManagement/repair/index"),
        meta: {
          title: "维修维护",
          noKeepAlive: true,
        },
      },
      {
        path: "repairMobileEdit",
        name: "RepairMobileEdit",
        component: () =>
          import(
            "@/views/farmingManagement/repair/components/RepairMobileEdit"
          ),
        meta: {
          title: "维修维护",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-维修维护")
            : (to.meta.title = "添加-维修维护");
          next();
        },
      },
      {
        path: "sales",
        name: "Sales",
        component: () => import("@/views/farmingManagement/sales/index"),
        meta: {
          title: "销售管理",
          noKeepAlive: true,
        },
      },
      {
        path: "salesMobileEdit",
        name: "SalesMobileEdit",
        component: () =>
          import("@/views/farmingManagement/sales/components/SalesMobileEdit"),
        meta: {
          title: "销售管理",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-销售管理")
            : (to.meta.title = "添加-销售管理");
          next();
        },
      },
    ],
  },
  {
    path: "/summaryReportManagement",
    component: Layout,
    redirect: "noRedirect",
    name: "SummaryReportManagement",
    meta: {
      title: "总结报告",
      icon: "chart-bar",
      permissions: ["admin"],
    },
    alwaysShow: true,
    children: [
      {
        path: "mortalityRate",
        name: "mortalityRate",
        component: () =>
          import("@/views/summaryReportManagement/mortalityRate/index"),
        meta: {
          title: "死亡率",
        },
      },
      // {
      //   path: "goose",
      //   name: "Goose",
      //   component: () => import("@/views/summaryReportManagement/goose/index"),
      //   meta: { title: "鹅" },
      // },
      // {
      //   path: 'incubation',
      //   name: 'Incubation',
      //   component: () => import('@/views/summaryReportManagement/incubation/index'),
      //   meta: { title: '孵化' },
      // },
    ],
  },
  {
    path: "/otherManagement",
    component: Layout,
    redirect: "noRedirect",
    name: "OtherManagement",
    meta: {
      title: "其他",
      icon: "grip-horizontal",
      permissions: ["admin"],
    },
    children: [
      {
        path: "visit",
        name: "Visit",
        component: () => import("@/views/otherManagement/visit/index"),
        meta: {
          title: "人员来访",
          noKeepAlive: true,
        },
      },
      {
        path: "visitMobileEdit",
        name: "VisitMobileEdit",
        component: () =>
          import("@/views/otherManagement/visit/components/VisitMobileEdit"),
        meta: {
          title: "人员来访",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-人员来访")
            : (to.meta.title = "添加-人员来访");
          next();
        },
      },
      {
        path: "logRecord",
        name: "LogRecord",
        component: () => import("@/views/otherManagement/logRecord/index"),
        meta: {
          title: "操作记录",
        },
      },
      {
        path: "dict",
        name: "Dict",
        component: () => import("@/views/otherManagement/dict/index"),
        meta: {
          title: "字典表",
          noKeepAlive: true,
        },
      },
      {
        path: "dictMobileEdit",
        name: "DictMobileEdit",
        component: () =>
          import("@/views/otherManagement/dict/components/DictMobileEdit"),
        meta: {
          title: "字典表",
          noKeepAlive: true,
        },
        hidden: true,
        beforeEnter: (to, _from, next) => {
          to.params.code
            ? (to.meta.title = "编辑-字典表")
            : (to.meta.title = "添加-字典表");
          next();
        },
      },
    ],
  },
  // {
  //   path: '/vab',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'Vab',
  //   alwaysShow: true,
  //   meta: { title: '组件', icon: 'box-open' },
  //   children: [
  //     {
  //       path: 'permissions',
  //       name: 'Permission',
  //       component: () => import('@/views/vab/permissions/index'),
  //       meta: {
  //         title: '角色权限',
  //         permissions: ['admin', 'editor'],
  //       },
  //     },
  //     {
  //       path: 'icon',
  //       component: EmptyLayout,
  //       redirect: 'noRedirect',
  //       name: 'Icon',
  //       meta: {
  //         title: '图标',
  //         permissions: ['admin'],
  //       },
  //       children: [
  //         {
  //           path: 'awesomeIcon',
  //           name: 'AwesomeIcon',
  //           component: () => import('@/views/vab/icon/index'),
  //           meta: { title: '常规图标' },
  //         },
  //         {
  //           path: 'colorfulIcon',
  //           name: 'ColorfulIcon',
  //           component: () => import('@/views/vab/icon/colorfulIcon'),
  //           meta: { title: '多彩图标' },
  //         },
  //       ],
  //     },
  //     {
  //       path: 'table',
  //       component: () => import('@/views/vab/table/index'),
  //       name: 'Table',
  //       meta: {
  //         title: '表格',
  //         permissions: ['admin'],
  //       },
  //     },
  //     {
  //       path: 'map',
  //       component: () => import('@/views/vab/map/index'),
  //       name: 'Map',
  //       meta: {
  //         title: '地图',
  //         permissions: ['admin'],
  //       },
  //     },

  //     {
  //       path: 'webSocket',
  //       name: 'WebSocket',
  //       component: () => import('@/views/vab/webSocket/index'),
  //       meta: { title: 'webSocket', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'form',
  //       name: 'Form',
  //       component: () => import('@/views/vab/form/index'),
  //       meta: { title: '表单', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'element',
  //       name: 'Element',
  //       component: () => import('@/views/vab/element/index'),
  //       meta: { title: '常用组件', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/vab/tree/index'),
  //       meta: { title: '树', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/vab/nested/menu1/index'),
  //       name: 'Menu1',
  //       alwaysShow: true,
  //       meta: {
  //         title: '嵌套路由 1',
  //         permissions: ['admin'],
  //       },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           name: 'Menu1-1',
  //           alwaysShow: true,
  //           meta: { title: '嵌套路由 1-1' },
  //           component: () => import('@/views/vab/nested/menu1/menu1-1/index'),

  //           children: [
  //             {
  //               path: 'menu1-1-1',
  //               name: 'Menu1-1-1',
  //               meta: { title: '嵌套路由 1-1-1' },
  //               component: () => import('@/views/vab/nested/menu1/menu1-1/menu1-1-1/index'),
  //             },
  //           ],
  //         },
  //       ],
  //     },
  //     {
  //       path: 'loading',
  //       name: 'Loading',
  //       component: () => import('@/views/vab/loading/index'),
  //       meta: { title: 'loading', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'backToTop',
  //       name: 'BackToTop',
  //       component: () => import('@/views/vab/backToTop/index'),
  //       meta: { title: '返回顶部', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'lodash',
  //       name: 'Lodash',
  //       component: () => import('@/views/vab/lodash/index'),
  //       meta: { title: 'lodash', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'smallComponents',
  //       name: 'SmallComponents',
  //       component: () => import('@/views/vab/smallComponents/index'),
  //       meta: { title: '小组件', permissions: ['admin'] },
  //     },

  //     {
  //       path: 'upload',
  //       name: 'Upload',
  //       component: () => import('@/views/vab/upload/index'),
  //       meta: { title: '上传', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'log',
  //       name: 'Log',
  //       component: () => import('@/views/vab/errorLog/index'),
  //       meta: { title: '错误日志模拟', permissions: ['admin'] },
  //     },
  //     {
  //       path: 'https://github.com/chuzhixin/vue-admin-beautiful?utm_source=gold_browser_extension',
  //       name: 'ExternalLink',
  //       meta: {
  //         title: '外链',
  //         target: '_blank',
  //         permissions: ['admin', 'editor'],
  //         badge: 'New',
  //       },
  //     },
  //     {
  //       path: 'more',
  //       name: 'More',
  //       component: () => import('@/views/vab/more/index'),
  //       meta: { title: '关于', permissions: ['admin'] },
  //     },
  //   ],
  // },
  // {
  //   path: '/personnelManagement',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'PersonnelManagement',
  //   meta: { title: '配置', icon: 'users-cog', permissions: ['admin'] },
  //   children: [
  //     {
  //       path: 'userManagement',
  //       name: 'UserManagement',
  //       component: () => import('@/views/personnelManagement/userManagement/index'),
  //       meta: { title: '用户管理' },
  //     },
  //     {
  //       path: 'roleManagement',
  //       name: 'RoleManagement',
  //       component: () => import('@/views/personnelManagement/roleManagement/index'),
  //       meta: { title: '角色管理' },
  //     },
  //     {
  //       path: 'menuManagement',
  //       name: 'MenuManagement',
  //       component: () => import('@/views/personnelManagement/menuManagement/index'),
  //       meta: { title: '菜单管理', badge: 'New' },
  //     },
  //   ],
  // },
  // {
  //   path: '/mall',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'Mall',
  //   meta: {
  //     title: '商城',
  //     icon: 'shopping-cart',
  //     permissions: ['admin'],
  //   },

  //   children: [
  //     {
  //       path: 'pay',
  //       name: 'Pay',
  //       component: () => import('@/views/mall/pay/index'),
  //       meta: {
  //         title: '支付',
  //         noKeepAlive: true,
  //       },
  //       children: null,
  //     },
  //     {
  //       path: 'goodsList',
  //       name: 'GoodsList',
  //       component: () => import('@/views/mall/goodsList/index'),
  //       meta: {
  //         title: '商品列表',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/error',
  //   component: EmptyLayout,
  //   redirect: 'noRedirect',
  //   name: 'Error',
  //   meta: { title: '错误页', icon: 'bug' },
  //   children: [
  //     {
  //       path: '401',
  //       name: 'Error401',
  //       component: () => import('@/views/401'),
  //       meta: { title: '401' },
  //     },
  //     {
  //       path: '404',
  //       name: 'Error404',
  //       component: () => import('@/views/404'),
  //       meta: { title: '404' },
  //     },
  //   ],
  // },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
});

export function resetRouter() {
  location.reload();
}

export default router;
